﻿using AutoMapper.Internal;
using FrameWork.Core;
using FrameWork.Core.Enum;
using FrameWork.Core.Utils;
using FrameWork.Device.Enum;
using FrameWork.Services;
using SqlSugar;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace AncheStart.Converter
{
    public class WorkStepTypeToChineseConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                Type type = typeof(EnumWorkStepType);
                if (GlobalConstant.EnumWorkStepFieldInfoDescriptionAttributes == null)
                {
                    value = value.ObjToInt(); 
                    GlobalConstant.EnumWorkStepFieldInfoDescriptionAttributes =Utils.GetFieldInfoDescriptionAttributes(type);

                }

                string propName = type.GetEnumName(value); 
                //通过值 获取
                string? workStepTypeval = GlobalConstant.EnumWorkStepFieldInfoDescriptionAttributes.FirstOrDefault(s => s.Name == propName)?.DescriptionAttribute?.Description;
                if (!string.IsNullOrEmpty(workStepTypeval))
                {
                    return workStepTypeval;
                }
                return "未定义:" + workStepTypeval;
            }
            catch (Exception ex)
            {
                return "未定义:" + value;
            }
        }

     

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

   
}